package com.itheima.dome;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

public class Student {
    /**
     * 姓名、年龄、性别，
     */
    private String name;
    private int age;
    private char sex;

    public Student() {
    }


    public Student(String name, int age, char sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && sex == student.sex && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, sex);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                ", sex=" + sex +
                '}';
    }


}

class Test{
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        list.add(new Student("小明",18,'男'));
        list.add(new Student("小美",23,'女'));
        list.add(new Student("晨曦",15,'女'));

        int maxAge=list.get(0).getAge();
        int index=0;
        for (int i = 1; i < list.size(); i++) {
            if (maxAge<=list.get(i).getAge()) {
                maxAge=list.get(i).getAge();
                index=i;
            }
        }

        list.get(index).setName("小猪佩奇");
        for (Student student : list) {
            System.out.println(student.toString());
        }



    }
}